package org.esprit.ocm.client.ui.ec2;

import org.esprit.ocm.dto.ec2.impl.KeyPairInfoMappingDto;
import org.esprit.ocm.dto.impl.AwsCredentialsDto;
import org.esprit.ocm.dto.impl.ServerDto;
import org.esprit.ocm.dto.impl.UserDto;

import com.smartgwt.client.types.Alignment;
import com.smartgwt.client.types.VerticalAlignment;
import com.smartgwt.client.widgets.Window;
import com.smartgwt.client.widgets.form.DynamicForm;
import com.smartgwt.client.widgets.form.fields.ButtonItem;
import com.smartgwt.client.widgets.form.fields.TextAreaItem;
import com.smartgwt.client.widgets.form.fields.events.ClickEvent;
import com.smartgwt.client.widgets.form.fields.events.ClickHandler;

public class GenerateKeyPair extends Window {

	public GenerateKeyPair(final ServerDto server, final AwsCredentialsDto credentials, final UserDto user, final KeyPairInfoMappingDto keyPair) {

		setTitle("Generate Private Key");
		setWidth(250);
		setHeight(450);
		setIsModal(true);
		setShowModalMask(true);
		setShowCloseButton(true);
		centerInPage();

		final DynamicForm formKeyPair = new DynamicForm();
		formKeyPair.setWidth(200);
		formKeyPair.setHeight(400);
		formKeyPair.setPadding(5);
		formKeyPair.setLayoutAlign(VerticalAlignment.TOP);

		TextAreaItem fingerPrintItem = new TextAreaItem();
		fingerPrintItem.setShowTitle(false);
		fingerPrintItem.setLength(5000);
		fingerPrintItem.setColSpan(2);
		fingerPrintItem.setWidth("*");
		fingerPrintItem.setHeight("*");
		fingerPrintItem.setValue(keyPair.getKeyMaterial());

		ButtonItem saveButton = new ButtonItem("save", "Save key");
		saveButton.setAlign(Alignment.CENTER);
		saveButton.addClickHandler(new ClickHandler() {

			public void onClick(ClickEvent event) {
				destroy();
			}
		});
		
		
		formKeyPair.setFields(fingerPrintItem, saveButton);
		formKeyPair.redraw();

		addItem(formKeyPair);
		
		draw();
	}
}
